<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - M3U8播放器</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <style>
        .auth-container {
            max-width: 400px;
            margin: 50px auto;
            padding: 0 15px;
        }
        
        .auth-card {
            background: white;
            border-radius: 8px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
            padding: 30px;
        }
        
        .auth-title {
            text-align: center;
            margin-bottom: 30px;
            font-size: 24px;
            color: #333;
        }
        
        .auth-form .form-group {
            margin-bottom: 20px;
        }
        
        .auth-form label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #333;
        }
        
        .auth-form input {
            width: 100%;
            padding: 10px 15px;
            border: 1px solid #d9d9d9;
            border-radius: 4px;
            font-size: 15px;
            transition: all 0.3s;
        }
        
        .auth-form input:focus {
            outline: none;
            border-color: #1890ff;
            box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
        }
        
        .auth-submit {
            width: 100%;
            padding: 12px;
            background: #1890ff;
            color: white;
            border: none;
            border-radius: 4px;
            font-size: 16px;
            cursor: pointer;
            transition: all 0.3s;
        }
        
        .auth-submit:hover {
            background: #40a9ff;
        }
        
        .auth-footer {
            text-align: center;
            margin-top: 20px;
            color: #666;
        }
        
        .auth-footer a {
            color: #1890ff;
            text-decoration: none;
        }
        
        .error-message {
            color: #ff4d4f;
            font-size: 13px;
            margin-top: 5px;
            display: none;
        }
    </style>
</head>
<body>
    <div class="auth-container">
        <div class="auth-card">
            <h1 class="auth-title">
                <i class="fas fa-sign-in-alt"></i>
                会员登录
            </h1>
            
            <form id="loginForm" class="auth-form">
                <input type="hidden" name="__token__" value="{:token()}">
                
                <div class="form-group">
                    <label for="username">用户名</label>
                    <input type="text" id="username" name="username" required>
                </div>
                
                <div class="form-group">
                    <label for="password">密码</label>
                    <input type="password" id="password" name="password" required>
                </div>
                
                <div id="errorMsg" class="error-message"></div>
                
                <button type="button" id="submitBtn" class="auth-submit">登录</button>
            </form>
            
            <div class="auth-footer">
                还没有账号？<a href="{:url('member/register')}">立即注册</a>
            </div>
        </div>
    </div>
    
    <script>
        document.getElementById('submitBtn').addEventListener('click', function() {
            var form = document.getElementById('loginForm');
            var errorMsg = document.getElementById('errorMsg');
            errorMsg.style.display = 'none';
            
            var username = document.getElementById('username').value.trim();
            var password = document.getElementById('password').value.trim();
            
            if (!username || !password) {
                errorMsg.textContent = '请输入用户名和密码';
                errorMsg.style.display = 'block';
                return;
            }
            
            fetch('{:url("member/doLogin")}', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'X-CSRF-TOKEN': document.querySelector('input[name="__token__"]').value
                },
                body: JSON.stringify({
                    username: username,
                    password: password
                })
            })
            .then(response => response.json())
            .then(data => {
                if (data.code === 200) {
                    window.location.href = '{:url("player/index")}';
                } else {
                    errorMsg.textContent = data.msg;
                    errorMsg.style.display = 'block';
                }
            })
            .catch(error => {
                errorMsg.textContent = '登录请求失败';
                errorMsg.style.display = 'block';
            });
        });
    </script>
</body>
</html>